<template>
  <div>
    <BasicTable @register="registerTable">
<!--      &lt;!&ndash;行内操作&ndash;&gt;
      <template #action="{ column, record, index }">
        <TableAction :actions="getTableAction(record)"/>
      </template>-->
    </BasicTable>
    <!--添加编辑-->
    <AreaDrawer @register="registerDrawer" @success="handleSuccess"/>
  </div>
</template>
<script lang="ts" setup name="area-list">
import {ActionItem, BasicTable, TableAction} from '@/components/table';
import {useDrawer} from '@/components/drawer';
import {useBaseTable} from '@/hooks/flyme/useBaseTable';

const [registerDrawer, {openDrawer}] = useDrawer();
import AreaDrawer from './components/AreaDrawer.vue';
import {Api} from './data/area.api';
import {columns} from './data/area.data';
//初始化Table
const {tableContext, handleSuccess} = useBaseTable({
  designScope: 'area-template',
  tableProps: {
    title: '区域表管理',
    columns: columns,
    //主键字段
    rowKey: 'areaId',
    pagination: false,
    striped: false,
    isTreeTable: true,
    //分页列表接口
    listUrl: Api.page,
    //是否显示索引列
    showIndexColumn: false,
    childrenColumnName: 'child',
    useSearchForm: false,
    showActionColumn:false,
    //操作列配置
    actionColumn: {
      fixed: 'right',
      width: 120,
    },
  },
});
const [registerTable, {reload}] = tableContext;

/**
 * 行内操作栏
 */
function getTableAction(record): ActionItem[] {
  return [
    {
      label: '编辑',
      icon: 'clarity:note-edit-line',
      onClick: handleEdit.bind(null, record),
    },
  ];
}

/**
 * 编辑事件
 * @param record
 */
function handleEdit(record) {
  openDrawer(true, {
    record,
    isUpdate: true,
  });
}
</script>
